{extend name="_container/table"}
{block name="left"}
<a href="{:url('add')}" class="layui-btn iframe" data-title="添加应用">添加应用</a>
{/block}

{block name="right"}
{/block}

{block name="table_header"}
<th>id</th>
<th>应用名称</th>
<th>系统应用</th>
<th>默认添加</th>
<th>操作</th>
{/block}

{block name="table_body"}
<tr>
    <td>{$v.id}</td>
    <td>{$v.name}</td>
    <td>{$v.is_sys?'是':'否'}</td>
    <td>
        <input type="checkbox" lay-text="是|否"  lay-skin="switch" value="1"  {$v.is_default?'checked':''} name="is_default" data-id="{$v.id}" ></td>
    <td>
        <a href="{:url('controller/index',['app_id'=>$v.id])}" class="layui-btn layui-btn-sm  iframe" data-height="100%" data-width="100%" data-title="{$v.name}应用控制器列表">控制器</a>
        {if !$v.is_sys}
        <a href="{:url('delete',['id'=>$v.id])}" class="layui-btn layui-btn-sm layui-btn-danger ajax_del">删除</a>
        {/if}
    </td>
</tr>
{/block}

{block name="table_footer"}
{/block}

{block name="js"}
<script>
    let form = layui.form;
    form.on('switch', function (data){
        let name = data.elem.name;
        let checked = data.elem.checked;
        let is_default = checked ? 1 : 0;
        if(name === 'is_default'){
            let id = $(data.elem).data('id');
            $.post("{:url('setSysField')}",{id, is_default},(res)=>{
                layer.msg(res.msg)
            })
        }

    })
</script>
{/block}
{/extend}
